﻿using System;
using System.Windows.Forms;
using System.Data.SqlClient;
using QuanLyTuyenSinh.Base;

namespace QuanLyTuyenSinh.PresentationLayer.Components
{
    public partial class frmDanhSBD : Form
    {
       private SqlConnection Conn;
        private SqlCommand Cmd;
        private string Sqlx;
        public frmDanhSBD()
        {
            InitializeComponent();
        }

        private void frmDanhSBD_Load(object sender, EventArgs e)
        {
            //Conn = ConnectData.Getcon();
            //Conn.Open();
            //comboKhoithi.DataSource = monthibus.GetKhoithiUngVoiNganhHoc();
            //comboKhoithi.DisplayMember = "Khoithi";
            //comboKhoithi.ValueMember = "Khoithi";
        }

        private void comboKhoithi_SelectedIndexChanged(object sender, EventArgs e)
        {
           // DataGridSBD.DataSource = thisinhbus.LoadTSDanhSBDTheoKhoithi(comboKhoithi.Text);    
            DataGridSBD.Columns[1].HeaderText = "Mã trường";
            DataGridSBD.Columns[2].HeaderText = "Khối thi";
            DataGridSBD.Columns[3].HeaderText = "Họ đệm";
            DataGridSBD.Columns[4].HeaderText = "Tên";
            DataGridSBD.Columns[5].HeaderText = "Giới tính";
            DataGridSBD.Columns[6].HeaderText = "Ngày sinh";
            DataGridSBD.Columns[7].HeaderText = "Nơi sinh";
            DataGridSBD.Columns[8].HeaderText = "Mã ngành";
            DataGridSBD.Columns[9].HeaderText = "Trường NV1";
            DataGridSBD.Columns[10].HeaderText = "Mã trường";
            DataGridSBD.Columns[11].HeaderText = "Khối thi";
            DataGridSBD.Columns[12].HeaderText = "Mã ngành";    
        }

        private void cmdDanhSBD_Click(object sender, EventArgs e)
        {
            try
            {
                string Khoithix = comboKhoithi.Text.ToString();
                Sqlx ="drop table "+Khoithix+" select 'SP2'+'" + comboKhoithi.Text + "'+ replace(str(row_number() over(order by Thisinh.Ten),5),' ','0') as SBD," +
                  "Thisinh.Phongthi,Thisinh.Hodem,Thisinh.Ten,Thisinh.Truongdkdt,Thisinh.Khtruong," +
                  "Thisinh.Khoithi,Thisinh.Manganh,NganhHoc.Tennganh,Thisinh.Truongnv,Thisinh.Khtruongnv," +
                  "Thisinh.Khoithinv,Thisinh.Manganhnv,Thisinh.Gioitinh,Thisinh.Ngaysinh,Thisinh.Noisinh," +
                  "Thisinh.Dantoc,Thisinh.Mauutien,Uutien.Diemdoituong,Thisinh.Hokhau,Thisinh.Matinh,DSTinh.Tentinh," +
                  "Thisinh.Mahuyen," +
                  "Thisinh.Lop10,Thisinh.Lop11,Thisinh.Lop12,Thisinh.Namtotnghiep,Thisinh.Noinophoso," +
                  "Thisinh.Madonvidk,Thisinh.Dienthoai,Thisinh.Ngaynophoso,Thisinh.Makhuvuc," +
                  "Khuvuc.Diemkhuvuc,Thisinh.PhachM1,Thisinh.PhachM2,Thisinh.PhachM3,Thisinh.TuiM1,Thisinh.TuiM2,Thisinh.TuiM3, " +
                  "Thisinh.DiemM1,Thisinh.DiemM2,Thisinh.DiemM3 "+
                " into " + comboKhoithi.Text.ToString().Trim() +
                  " from Thisinh join NganhHoc on NganhHoc.Manganh=Thisinh.Manganh " +
                                "join Uutien on Uutien.Madoituong=Thisinh.Mauutien " +
                                "join DSTinh on DSTinh.Matinh=Thisinh.Matinh " +
                                "join Khuvuc on Khuvuc.Makhuvuc=Thisinh.Makhuvuc " +
                    " where Thisinh.Khoithi='" + comboKhoithi.Text + "'" +
                  " order by Thisinh.Ten";
                Cmd = new SqlCommand(Sqlx, Conn);
                Cmd.ExecuteNonQuery();
              //  DataGridSBD.DataSource = thisinhbus.LoadDLSauKhiDanhSBD(comboKhoithi.Text);
                MessageBox.Show("Đánh số báo danh cho khối " + comboKhoithi.Text.ToString() + " thành công!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

       }
}
